package com.leetcode.LC;

import java.util.ArrayList;
import java.util.HashMap;

public class LC884 {
    public String[] uncommonFromSentences(String A, String B) {

        String[] s = A.split(" ");
        String[] s1 = B.split(" ");
        HashMap<String, Integer> map = new HashMap<>();

        for (String s2 : s) {
            if (map.containsKey(s2)) {
                map.put(s2, map.get(s2) + 1);
            } else {
                map.put(s2, 1);
            }
        }
        for (String s2 : s1) {
            if (map.containsKey(s2)) {
                map.put(s2, map.get(s2) + 1);
            } else {
                map.put(s2, 1);
            }
        }
        ArrayList<String> list = new ArrayList<>();
        for (String s2 : map.keySet()) {
            if (map.get(s2) == 1) {
                list.add(s2);
            }
        }
        return list.toArray(new String[list.size()]);

    }

    public static void main(String[] args) {
        for (String s : new LC884().uncommonFromSentences("apple apple","banana")) {
            System.out.println(s);
        }
    }
}
